package com.outsider.note.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.outsider.note.dao.TextNote;
import com.outsider.note.task.NoteTimerTask;
import com.outsider.note.task.TextNoteTimerTask;
import com.outsider.util.Const;
import com.outsider.util.ScheduleUtil;
import com.outsider.weixin.dao.User;

public class TextNoteService {
	public void saveTextNote(String msgContent,String openID) {
		 Integer userID=User.dao.findIDbyOpenID(openID);
		 String msg[]=msgContent.split(" ", 4); 
		 Date date = null;
		 try {
			date=Const.SDF.parse(msg[1]+" "+msg[2]);
		} catch (ParseException e) {
			e.printStackTrace();
		}
         
		 TextNote textNote=new TextNote().set(Const.DATE, date).set("MSG", msg[3]);
		 textNote.setUserId(userID);
		 textNote.save();
		 ScheduleUtil.getScheduleUtil().addTask(new TextNoteTimerTask(textNote));
	}
	public void deleteTextNote(TextNote textNote){
		ScheduleUtil.getScheduleUtil().deleteTask(textNote);
		textNote.delete();
		
	}
}
